/*******************************************************************************
 * Copyright (c) 2001, 2002 Boris Pruessmann and others. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Common Public License v0.5 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.ui.prefs;

import net.sourceforge.perforce.ui.IPerforceUIConstants;
import net.sourceforge.perforce.ui.PerforceUIPlugin;
import net.sourceforge.perforce.ui.internal.Policy;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.RadioGroupFieldEditor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
 * @version $Revision: 1.3 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 */
public class P4PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
  // -------------------------------------------------------------------------
  // Public Constructors

  /** Constructor for P4PreferencePage. */
  public P4PreferencePage() {
    super(FieldEditorPreferencePage.GRID);
    setPreferenceStore(PerforceUIPlugin.getPlugin().getPreferenceStore());
  }

  //----------------------------------------------------------------------------
  // -- Public Methods

  public void init(IWorkbench workbench) {
  }

  // ---------------------------------------------------------------------------
  // Protected Methods

  @Override
  protected void createFieldEditors() {
    Label label = new Label(getFieldEditorParent(), SWT.NULL);
    label.setText("General Perforce settings:");
    label.setFont(JFaceResources.getDialogFont());

    BooleanFieldEditor deleteAffectesChangelist =
        new BooleanFieldEditor(PerforceUIPlugin.DELETE_AFFECTS_CHANGELIST, Policy
            .bind("PerforcePreferencePage.deleteAffectsChangelist"), //$NON-NLS-1$
            getFieldEditorParent());
    addField(deleteAffectesChangelist);

    BooleanFieldEditor showTasksOnAdd =
        new BooleanFieldEditor(IPerforceUIConstants.PREF_SHOW_TASKS_ON_ADD, "Show added markers",
            getFieldEditorParent());
    addField(showTasksOnAdd);

    BooleanFieldEditor projectNamesShowFullPath =
        new BooleanFieldEditor(IPerforceUIConstants.PREF_SHOW_FULLPATH_FOR_PROJECTS,
            "Show full depot path for Projects", getFieldEditorParent());
    addField(projectNamesShowFullPath);

    BooleanFieldEditor dontPromptOnOpen =
        new BooleanFieldEditor(IPerforceUIConstants.PREF_DONT_PROMPT_AUTOMATIC_OPEN,
            "Automatically open files on edit", getFieldEditorParent());
    addField(dontPromptOnOpen);

    BooleanFieldEditor warnOnOtherOpen =
        new BooleanFieldEditor(IPerforceUIConstants.PREF_WARN_ON_OTHER_OPEN,
            "Warn when opening files that are also opened by others.", getFieldEditorParent());
    addField(warnOnOtherOpen);

    Group group = new Group(getFieldEditorParent(), SWT.SHADOW_NONE);
    group.setText("Submit options");

    BooleanFieldEditor checkNewFiles =
        new BooleanFieldEditor(IPerforceUIConstants.PREF_CHECK_FOR_NEWFILES_BEFORE_SUBMIT,
            "Prompt to add 'new' files before changelist submission.", group);
    addField(checkNewFiles);

    BooleanFieldEditor checkChangelists =
        new BooleanFieldEditor(IPerforceUIConstants.PREF_CHECK_CHANGELIST_FOR_WARNINGS_AND_ERROR,
            "Warn when submitting changelist that has warnings/errors", group);
    addField(checkChangelists);

    RadioGroupFieldEditor unsavedResourcesBehavior =
        new RadioGroupFieldEditor(IPerforceUIConstants.PREF_UNSAVED_RESOURCES_BEHAVIOR,
            "When Submitting Unsaved Resources ...", 1, new String[][] {
                {"Submit Anyway", IPerforceUIConstants.URB_SUBMIT},
                {"Prompt User", IPerforceUIConstants.URB_PROMPT},
                {"Save and Submit", IPerforceUIConstants.URB_AUTOSAVE},}, group);
    addField(unsavedResourcesBehavior);
    Label filler = new Label(group, SWT.NONE);
    filler.setText(" ");
    group.pack(true);
  }
}
